package com.vaadin.lab1;

import com.vaadin.Application;
import com.vaadin.ui.*;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.themes.Reindeer;

@SuppressWarnings("serial")
public class Lab extends Application {

	private HorizontalLayout view;
	
    @Override
    public void init() {

        Window mainWindow = new Window("Lab");
        setMainWindow(mainWindow);
        
        GridLayout grid = new GridLayout(2, 2);
        mainWindow.setContent(grid);
        grid.setSizeFull();
        
        VerticalLayout left = new VerticalLayout();
        HorizontalLayout top = new HorizontalLayout();
        
        view = new HorizontalLayout();
        view.setStyleName(Reindeer.LAYOUT_BLACK);
        view.setSizeFull();
        
        left.setWidth("-1");
        top.setHeight("-1");
        grid.setColumnExpandRatio(1, 1);
        grid.setRowExpandRatio(1, 1);
        
        grid.addComponent(left, 0, 1);
        grid.addComponent(top, 1, 0);
        grid.addComponent(view, 1, 1);
        
        Button hb1 = new Button("View 1");
        Button hb2 = new Button("View 2");
        Button hb3 = new Button("View 3");
        
        Button vb1 = new Button("View 1");
        Button vb2 = new Button("View 2");
        Button vb3 = new Button("View 3");
        
        hb1.addListener(getBlueClickListener());
        hb2.addListener(getWhiteClickListener());
        hb3.addListener(getBlackClickListener());
        
        vb1.addListener(getBlueClickListener());
        vb2.addListener(getWhiteClickListener());
        vb3.addListener(getBlackClickListener());
        
        left.addComponent(vb1);
        left.addComponent(vb2);
        left.addComponent(vb3);
        
        top.addComponent(hb1);
        top.addComponent(hb2);
        top.addComponent(hb3);
        	
        grid.setComponentAlignment(top, Alignment.MIDDLE_RIGHT);
    }

	private ClickListener getBlueClickListener() {
		return new ClickListener() {
			
			@Override
			public void buttonClick(ClickEvent event) {
				view.setStyleName(Reindeer.LAYOUT_BLUE);
			}
		};
	}
	private ClickListener getWhiteClickListener() {
		return new ClickListener() {
			
			@Override
			public void buttonClick(ClickEvent event) {
				view.setStyleName(Reindeer.LAYOUT_WHITE);
			}
		};
	}
	private ClickListener getBlackClickListener() {
		return new ClickListener() {
			
			@Override
			public void buttonClick(ClickEvent event) {
				view.setStyleName(Reindeer.LAYOUT_BLACK);
			}
		};
	}
}